    <template>
        <div>
            <el-card class="!border-none" shadow="never">
                <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                    <el-form-item class="w-[280px]" label="主体名称">
                        <el-input v-model="queryParams.entity_name" placeholder="请输入主体名称" clearable
                            @keyup.enter="resetPage" />
                    </el-form-item>
                    <el-form-item label="提交时间">
                        <daterange-picker v-model:startTime="queryParams.start_time"
                            v-model:endTime="queryParams.end_time" />
                    </el-form-item>
                    <!-- <el-form-item class="w-[280px]" label="注册来源">
                        <el-select v-model="queryParams.channel">
                            <el-option v-for="(item, key) in ClientMap" :key="key" :label="item" :value="key" />
                        </el-select>
                    </el-form-item> -->
                    <el-form-item>
                        <el-button type="primary" @click="resetPage">查询</el-button>
                        <el-button @click="resetParams">重置</el-button>
                        <export-data class="ml-2.5" :fetch-fun="getPlantingList" :params="queryParams"
                            :page-size="pager.size" />
                    </el-form-item>
                </el-form>
            </el-card>
            <el-card class="!border-none mt-4" shadow="never">
                <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                    <el-table-column label="提交人手机号" prop="user_account" min-width="120" />
                    <el-table-column label="主体名称" prop="entity_name" min-width="100" />
                    <el-table-column label="统一社会信用代码" prop="credit_code" min-width="100" />
                    <el-table-column label="成立日期" prop="start_date" min-width="100" />
                    <el-table-column label="法定代表人姓名" prop="oper_name" min-width="100" />
                    <el-table-column label="状态" prop="status" min-width="100" />
                    <el-table-column label="注册号" prop="no" min-width="100" />
                    <el-table-column label="地址" prop="comp_address" min-width="100" />
                    <el-table-column label="身份证号" prop="id_card" min-width="120" />
                    <el-table-column label="所在地区" prop="address" min-width="120" />
                    <el-table-column label="详细地址" prop="address_detail" min-width="120" />
                    <el-table-column label="种植地名称" prop="field_name" min-width="120" />
                    <el-table-column label="位置" prop="location" min-width="120" />
                    <el-table-column label="品种来源" prop="variety_source" min-width="120" />
                    <el-table-column label="种植面积" prop="planting_area" min-width="120" />
                    <el-table-column label="种植时间" prop="planting_date" min-width="120" />
                    <el-table-column label="预计作货时间" prop="estimated_harvest_date" min-width="120" />
                    <el-table-column label="预计作货量" prop="estimated_yield" min-width="120" />
                    <el-table-column label="累计采收次数" prop="total_harvest_times" min-width="120" />
                    <el-table-column label="累计作货量" prop="total_yield" min-width="120" />
                    <el-table-column label="预计剩余作货量" prop="remaining_yield" min-width="120" />
                    <el-table-column label="流转情况" prop="circulation_info" min-width="120" />
                    <el-table-column label="承包情况" prop="contract_info" min-width="120" />
                    <el-table-column label="权属情况" prop="ownership_info" min-width="120" />
                    <el-table-column label="检测报告图片" min-width="200">
                        <template #default="{ row }">
                            <div v-if="row.report_images">
                                <el-image v-for="(image, index) in row.report_images.split(',')" :key="index"
                                    :src="config.baseUrl + image" fit="cover"
                                    style="width: 50px; height: 50px; margin-right: 10px"
                                    @click="openImageGallery(row.report_images.split(','), index)" />
                            </div>
                            <span v-else style="color: red">无图片</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="种植环境照片" min-width="200">
                        <template #default="{ row }">
                            <div v-if="row.environment_images">
                                <el-image v-for="(image, index) in row.environment_images.split(',')" :key="index"
                                    :src="config.baseUrl + image" fit="cover"
                                    style="width: 50px; height: 50px; margin-right: 10px"
                                    @click="openImageGallery(row.environment_images.split(','), index)" />
                            </div>
                            <span v-else style="color: red">无图片</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="提交时间" prop="create_time" min-width="120" />
                    <el-table-column label="操作" width="120" fixed="right">
                        <template #default="{ row }">
                            <el-button v-perms="['user.user/detail']" type="primary" link>
                                <router-link :to="{
                                    path: getRoutePath('user.user/detail'),
                                    query: {
                                        id: row.id
                                    }
                                }">
                                    详情
                                </router-link>
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-dialog v-model="dialogVisible" :title="'图片查看'" width="50%">
                    <el-carousel v-if="imageList.length" v-model="currentImageIndex" arrow="always">
                        <el-carousel-item v-for="(image, index) in imageList" :key="index">
                            <el-image :src="image" fit="contain" style="width: 100%; height: 200px" />
                        </el-carousel-item>
                    </el-carousel>
                </el-dialog>
                <div class="flex justify-end mt-4">
                    <pagination v-model="pager" @change="getLists" />
                </div>
            </el-card>
        </div>
    </template>
<script lang="ts" setup name="consumerLists">
import config from '@/config'
import { ref } from 'vue'
import { getPlantingList } from '@/api/Planting'
import { ClientMap } from '@/enums/appEnums'
import { usePaging } from '@/hooks/usePaging'
import { getRoutePath } from '@/router'

const formRef = ref(null)
const queryParams = reactive({
    entity_name: '',
    channel: '',
    start_time: '',
    end_time: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: getPlantingList,
    params: queryParams
})

// 组件激活时获取列表数据
onActivated(() => {
    getLists()
})
getLists()
// // 组件挂载时获取列表数据
// onMounted(() => {
//     getLists()
// })

// 弹窗是否显示
const dialogVisible = ref(false)
// 当前图片列表
const imageList = ref<string[]>([])
// 当前图片索引
const currentImageIndex = ref(0)

// 打开图片浏览工具
const openImageGallery = (images: string[], index: number) => {
    imageList.value = images.map(img => config.baseUrl + img)
    currentImageIndex.value = index
    dialogVisible.value = true
}
</script>
<style scoped lang="scss">
.el-form-item__label {
    font-weight: 500;
}
</style>
